package com.forever7776.life.web.controller.life.m;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.forever7776.life.core.common.vo.UserBlogSearchVO;
import com.forever7776.life.core.entity.Tweets;
import com.forever7776.life.core.entity.blog.Blog;
import com.forever7776.life.core.service.ITweetsService;
import com.forever7776.life.core.service.blog.IBlogService;
import com.forever7776.life.web.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 我的动弹
 *
 * @author kz
 * @date 2018年02月10日
 */
@Controller
@RequestMapping(value = "/m/tweets")
public class MyTweetsController extends BaseController {

    @Autowired
    private ITweetsService iTweetsService;

    @RequestMapping
    public String index() {
        return USER_VIEW_PAGE_PATH + "tweets/index";
    }

    @RequestMapping("/list")
    @ResponseBody
    public JSONObject list() {
        JSONObject result = new JSONObject();
        Page<Tweets> page = iTweetsService.selectAll(new Page<Tweets>(pageNumber, pageSize), getUserId(), null);
        result.put("page", page);
        return result;
    }

    /**
     * 查询博客数量
     *
     * @return
     */
    @RequestMapping(value = "/count", method = RequestMethod.GET)
    @ResponseBody
    public JSONObject count() {
        JSONObject result = new JSONObject();
        result.put("count", iTweetsService.selectCount(new EntityWrapper<Tweets>().eq("user_id", getUserId())));
        return result;
    }
}
